package com.xian.ucenter.controller.front;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xian.ucenter.commons.Result;
import com.xian.ucenter.entities.Project;
import com.xian.ucenter.service.impl.ProjectServiceImpl;
import com.xian.ucenter.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/ucenter/front/project")
public class ProjectFrontController {
    @Autowired
    private ProjectServiceImpl projectService;
    @Resource
    private PageUtil<Project> projectPageUtil;
    @RequestMapping("/{current}")
    public Result getProjects(@PathVariable("current") Integer current) {
        QueryWrapper<Project> projectQueryWrapper = new QueryWrapper<>();
        projectQueryWrapper.eq("status",0);
        return projectPageUtil.pageList(current,6,projectService,projectQueryWrapper);
    }
    @RequestMapping("/getProject/{projectId}")
    public Result getProjectById(@PathVariable("projectId") String projectId) {
        Project project = projectService.getById(projectId);
        if (ObjectUtil.isNull(project)) {
            throw new RuntimeException("项目不存在！");
        }
        return Result.ok("project",project);
    }
}
